<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="4" :sm="4">
            <a-form-item
              label="科室"
              :maxLength="50">
              <a-input
                      v-model="queryParam.departCode"
                      placeholder="请输入"
                      type="hidden"/>
              <depart-window-show
                      :org-flag="-1"
                      :multiple-flag="true"
                      :checkedDepartKeys="queryParam.departCode"
                      @ok="departOk"
              ></depart-window-show>

            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item
              label="日期范围"
              :maxLength="50">
              <a-range-picker @change="onChange" v-model="queryParam.timeinfo" format="YYYY-MM-DD"/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item
              label="核酸次数"
              :maxLength="50">
              <a-select v-model="queryParam.number" placeholder="请选择次数">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option
                  v-for="(item) in this.$sysDictOptions('hesuannum')"
                  :key="item.k"
                  :value="parseInt(item.k)">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item
              label="姓名"
              :maxLength="50">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)" icon="search">查询</a-button>
              <a-button
                @click="() => {this.$objToReset(queryParam),this.depart=undefined,$refs.table.refresh(true)}"
                icon="reload"
                style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator">
        <a-button
            @click="exportExcelPatient()"
            type="primary"
            style="margin-bottom: 10px"
            icon="download"
        >患者陪护导出</a-button>
        <span style="font-size: 15px;font-weight: bolder;color: #006aeb;"> 当前患者+陪护统计人次：<span style="color: red;font-size: 16px;">{{totals}}人</span></span>
      </div>
      <s-table
        ref="table"
        rowKey="id"
        size="middle"
        pageSize="20"
        :scroll="{ x: 1500 }"
        :columns="columns"
        :alert="options.alert"
        :data="loadData"
        >
      </s-table>
      <hos-works-edit ref="modalEdit" @ok="modalEditOk"></hos-works-edit>
      <hos-works-view ref="modalView"></hos-works-view>
    </div>
  </a-card>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { deleteAction, fileAction, postAction } from '@/api/manage'
  import { mixin } from '@/utils/mixin'
  import HosWorksEdit from './HosWorksEdit'
  import HosWorksView from './HosWorksView'
  import DepartWindowShow from "../../../components/WxDepartChoose/DepartWindowShow";

  export default {
    name: 'HosWorksList',
    mixins: [mixin],
    components: {DepartWindowShow, STable, Ellipsis, HosWorksEdit, HosWorksView },
    data () {
      return {
        visible: false,
        typeName: '',
        // 查询条件
        queryParam: {
          title: '',
          times: '',
          number: '',
          state: 1
        },
          totals:'0',
        // 表头
        // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
        columns: [
          {
            title: '人员分类',
            dataIndex: 'tye',
            customRender: (text) => '30'
          },
          {
            title: '分类名称',
            dataIndex: 'typeName',
            customRender: (text) => '普通医疗机构'
          },
          {
            title: '统计时间',
            width: 200,
            dataIndex: 'times'
          },
          {
            title: '科室姓名',
            dataIndex: 'depart',
              customRender: (text) => this.$getDepartmentName(text)==''?text:this.$getDepartmentName(text)
          },
          {
            title: '姓名',
            dataIndex: 'name'
          },
          {
            title: '身份证号',
            dataIndex: 'idcard'
          },
          // {
          //   title: '应检次数',
          //   dataIndex: 'shouldNum',
          //   customRender: (text) => '2'
          // },
          {
            title: '实检次数',
            dataIndex: 'heyanCount'
          }
          // {
          //   title: '备注',
          //   dataIndex: 'remark',
          //   width: 300
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align: 'center',
          //   fixed: 'right',
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          var that = this
          console.log('loadData.parameter', parameter)
          return postAction(this.url.list, Object.assign(parameter, this.queryParam))
              .then(res => {
                 that.totals = res.result.data.total
                return res.result
              })
        },
        selectedRowKeys: [],
        options: {
          alert: {
            clear: () => {
              this.selectedRowKeys = []
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'checkbox'
          }
        },
        url: {
          list: '/system/nurseTaskDetail/listCountf',
          delete: '/system/hosWorks/delete',
          listcountExcel: '/system/hosWorks/listcountExcel',
          listcountExcelPatient: '/system/hosWorks/listcountExcelPatient',
          getDeptList: '/system/hosWorks/getDeptlist'
        },
        depart: undefined,
        deptList: []
      }
    },
    computed: {},
    mounted () {

    },
    methods: {
      // 删除
      handleDelete (record) {
        if (!record) {
          // 如果没有传入，那么批量删除
          record = this.selectedRowKeys.join(',')
        }
        deleteAction(this.url.delete, { ids: record }).then((resp) => {
          this.$message.success('删除成功!')
          this.$refs.table.refresh(true)
        })
      },
      // 用户编辑
      handleEdit (record) {
        this.$refs.modalEdit.edit(record)
      },
      searchQuery () {
        this.$refs.table.refresh(true)
      },
        departOk (val) {
            this.queryParam.departCode = val
        },
      getDeptList () {
        postAction(this.url.getDeptList, {})
            .then(res => {
              this.deptList = res.result.data
            })
      },
      selectdept () {
        this.queryParam.depart = this.depart.join(',')
      },
      // 保存刷新
      modalEditOk () {
        this.$refs.table.refresh()
      },
      // 查看
      handelView (record) {
        this.$refs.modalView.show(record)
      },
      onChange (value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.times = dateString[0] + '~' + dateString[1]
      },
      exportExcel () {
        fileAction(this.url.listcountExcel, Object.assign(this.queryParam))
            .then(res => {
              console.log(this.data1)
            })
      },
      exportExcelPatient () {
        fileAction(this.url.listcountExcelPatient, Object.assign(this.queryParam))
            .then(res => {
              console.log(this.data1)
            })
      },
      // 开启选择
      onSelectChange (selectedRowKeys) {
         console.log('selectedRowKeys changed: ', selectedRowKeys)
         this.selectedRowKeys = selectedRowKeys
      }
    },
    watch: {}
  }
</script>
<style scoped>
</style>
